home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 16384 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  64 lines

  1. Newsgroups: comp.lang.c++
  2. Path: oce.nl!not-for-mail!news
  3. From: qqehe@oce.nl (Emile Heyns)
  4. Subject: Pointer to non-static method
  5. X-Nntp-Posting-Host: tg17-pos
  6. Message-ID: <Dpn2MG.9y0@oce.nl>
  7. Sender: news@oce.nl (The Daily News @ nntp01.oce.nl)
  8. Organization: Oce Nederland B.V. - Research & Development
  9. X-Newsreader: knews 0.9.3
  10. Date: Wed, 10 Apr 1996 09:06:16 GMT
  11.  
  12. Hi all,
  13.  
  14. I am looking for a way to store and use a pointer to a method. I will
  15. be using this pointer from within another method of the same object
  16. (I will remain "within" the object). So far, I have been using thus
  17. kludge:
  18.  
  19. =====
  20. class object {
  21.   static object* This;
  22.  
  23.   static void method1(int x, int y);
  24.   static void method2(int x, int y);
  25.  
  26.   void method3(...);
  27.   void method4(...);
  28. };
  29.  
  30. object::object(...)
  31. {
  32.   This = this;
  33. }
  34.  
  35. void object::method3(...)
  36. {
  37.   function_pointer = condition ? method1 : method2;
  38. }
  39.  
  40. void object::method1(int x, int y)
  41. {
  42.   do something with This;
  43. }
  44. =====
  45.  
  46. but this will limit me to instantiating only one object of this class.
  47. Any ideas?
  48.  
  49. -- 
  50. Bye,
  51.  
  52. Emile
  53.  
  54. ===========================================================
  55. Emile Heyns email: emile.heyns@hta.nl
  56. ===========================================================
  57. Disclaimer: the opinions in this messages are *mine*, and
  58. have *no* bearing whatsoever on the opinions of the company.
  59. So there.
  60.  
  61. Never make anything simple and efficient when a way can be found to
  62. make it complex and wonderful.
  63.  
  64.